/**
 * 
 */
package com.onstar.cn.map.route;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;

import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.model.LatLng;


/**
 * @author Qiying Gong
 * 
 * @Created 2013-5-23
 */
public class ORouteOverlay {

	private List<LatLng> shapes;

	private Paint paint;
	

	public ORouteOverlay(List<LatLng> shapes,Paint paint) {
		this.shapes = shapes;
		this.paint = paint;
	}



	public void draw(Canvas canvas, AMap mapView, boolean arg2) {
//		super.draw(canvas, mapView, arg2);

		Paint linePaint = new Paint();
		linePaint.setAntiAlias(true);
		linePaint.setColor(Color.BLUE);
		linePaint.setStrokeWidth(6);
		linePaint.setStrokeCap(Paint.Cap.ROUND);
		linePaint.setStyle(Paint.Style.STROKE);
		linePaint.setAlpha(192);
		List<Point> list = this.getScrPoints(mapView);
//		int level = mapView.getZoomLevel();
		int i=0;
		int step = 1;
		int size = shapes.size();
//		if (level < 9 ) {
//			if(size > 500 ){
//				step = 5;
//			}
//		}
		
		Point pt1 = list.get(i);
		for (; i < list.size() - step; ) {
			
			Point pt2 = list.get(i);
			canvas.drawLine(pt1.x, pt1.y, pt2.x, pt2.y, linePaint);
			i = i+ step;
			pt1 = pt2;
		}
		
	}
	
	private List<Point> getScrPoints(AMap mapView){
		List<Point> list = new ArrayList<Point>();
		for (int i = 0; i < this.shapes.size() - 1; i++) {
			Point pt1 = mapView.getProjection().toScreenLocation(shapes.get(i));
			list.add(pt1);
		}
		
		return list;
	}

}
